package org.jeecg.modules.demo3.fly.utils;

import com.alibaba.fastjson.JSON;
import org.jeecg.modules.demo3.fly.entity.tcp.DistributionDataBean;

import java.io.*;
import java.util.ArrayList;

/**
 * @author wjn
 * @version V1.0
 * @date 2021/6/2 8:54
 * @Copyright © 2021/6/2 深圳卓翼航空无人机有限公司
 */
// 读取本地文件数据
public class FileRead {

    public DistributionDataBean getFileRead(int serialNumber,int month,String year,String dayas){ //接受一个完整的 文件路劲
        System.out.println(dayas);
        DistributionDataBean distributionDataBean = null;
        String fileName = "C:\\OS\\fly\\"+serialNumber+"\\"+year+"\\"+month;
        String pathName = dayas; //储蓄路劲
        File file = null;
        if(null != pathName){
           file = new File(fileName,pathName);
        }else{
            return null;
        }
        BufferedReader bufferedReader = null;
        boolean A_B = true;
        if(file.exists()) {
            try {
                FileReader fileReader = new FileReader(file);
                while(A_B){
                    try{
                        bufferedReader = new BufferedReader(fileReader);
                        String str;
                        while((str = bufferedReader.readLine()) != null){
                            distributionDataBean = JSON.parseObject(str,DistributionDataBean.class);
                        }
                    }catch(EOFException e){
                        break;
                    }catch(NullPointerException ee){
                        continue;
                    }
                    A_B = false;
                }
                bufferedReader.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }else{
            return null;
        }
      return distributionDataBean;
    }
}
